<?php
class WordsAction extends Action{
	public function showWordsByName($authorName){
		//根据作者名称，模糊查找名言，组装页面
		$author = D('author');
		$authorList = $author->getAuthorByName($authorName);
		
		//选定数组中第一个作者的信息来显示
		$chosenAuthor = $authorList[0];
		
		$aid = $chosenAuthor['aid'];
		//提取背景图片信息
		$bgPicture = M('background');
		$con['aid'] = $aid;
		$bgPicList = $bgPicture->where($con)->select();
		$chosenBgPic = $bgPicList[0];
		//提取所有的名言
		$words = M('words');
		$wordsList = $words->field('content')->where($con)->select();
		
		//组装JS全局变量 authorWords
		$authorWords = "<script>var authorWords=".json_encode($wordsList)."</script>";
		
		$firstWords = $wordsList[0]['content'];
		
		$this->assign('title','巨匠随谈');
		$this->assign('authorWords',$authorWords);
		$this->assign('firstWords',$firstWords);
		if($chosenAuthor['chname'] != ""){
			$this->assign('authorName',($chosenAuthor['chname']));
		}else if($chosenAuthor['enname'] != ""){
			$this->assign('authorName',($chosenAuthor['enname']));
		}else{
			$this->assign('authorName',($chosenAuthor['nkname']));
		}
				
		$this->display("Words:showWords");
	}
	
	public function showWordsById(){
		//echo $_GET['aid'];
		$aid = $_GET['aid'];
		//根据作者名称，模糊查找名言，组装页面
		$author = M('author');
		$con['aid'] = $aid;		
		$chosenAuthor = $author->where($con)->find();
				
		//提取背景图片信息
		$bgPicture = M('background');
		
		$bgPicList = $bgPicture->where($con)->select();
		$chosenBgPic = $bgPicList[0];
		//提取所有的名言
		$words = M('words');
		$wordsList = $words->field('content')->where($con)->select();
		
		//echo(json_encode($wordsList));
		
		//组装JS全局变量 authorWords
		$authorWords = "<script>var authorWords=".json_encode($wordsList)."</script>";
		
		$firstWords = $wordsList[0]['content'];
		
		$this->assign('title','巨匠随谈');
		$this->assign('authorWords',$authorWords);
		$this->assign('firstWords',$firstWords);
		$this->assign('bgImage',$chosenBgPic['imgurl']);
		if($chosenAuthor['chname'] != ""){
			$this->assign('authorName',($chosenAuthor['chname']));
		}else if($chosenAuthor['enname'] != ""){
			$this->assign('authorName',($chosenAuthor['enname']));
		}else{
			$this->assign('authorName',($chosenAuthor['nkname']));
		}
				
		$this->display("Words:showWords");
	}		
	
}
?>